package com.hc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.constant.SkuConst;
import com.hc.domain.Spu;
import com.hc.mapper.SpuMapper;
import com.hc.res.SpuDetail;
import com.hc.service.BrandService;
import com.hc.service.CountryService;
import com.hc.service.SpuService;
import com.hc.trans.SpuTrans;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author hecai
 * @date 2021/12/7 15:10
 */
@Service
public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuService {

    @Resource
    private BrandService brandService;
    @Resource
    private CountryService countryService;

    @Override
    public SpuDetail getSpuDetailBySpuId(Integer spuId) {
        QueryWrapper<Spu> spuQueryWrapper = new QueryWrapper<Spu>()
                .select("name", "caption", "specs", "brand_id", "service", "info", "country_id", "addr")
                .eq("id", spuId)
                .eq("status", SkuConst.Status.ok);
        Spu spu = baseMapper.selectOne(spuQueryWrapper);
        SpuDetail spuDetail = SpuTrans.MAPPER.spu2SpuDetail(spu);
        //设置商标名称
        String brandName = brandService.getById(spuDetail.getBrandId()).getName();
        spuDetail.setBrandName(brandName);
        //获取省市县名称
        String pcc = countryService.selectProvinceCityCountryByCountryId(spuDetail.getCountryId());
        spuDetail.setProvinceCityCountry(pcc);
        return spuDetail;
    }
}
